package org.delphy.crimson
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.filters.DropShadowFilter;
	import flash.filters.GlowFilter;
	import flash.geom.Matrix;
	
	import mx.controls.List;
	import mx.controls.listClasses.IListItemRenderer;
	

	public class CrimsonList extends List
	{
		[Embed('images/ListSelected.png')]
		private var selectedIndicator:Class;
		
		public function CrimsonList()
		{
			super();
			
			styleName="crimsonList";
		}
		
		 override protected function drawSelectionIndicator(
	                                indicator:Sprite, x:Number, y:Number,
	                                width:Number, height:Number, color:uint,
	                                itemRenderer:IListItemRenderer):void
	    {
	    	/*
	        var g:Graphics = Sprite(indicator).graphics;
	        g.clear();
	        
	        var gradientBoxMatrix:Matrix = new Matrix();
			gradientBoxMatrix.createGradientBox(width,height, Math.PI/2, 0, 0);
			g.lineGradientStyle(GradientType.LINEAR, [0x1096c3, 0x1096c3], [1, 1], [0,  255], gradientBoxMatrix);
			g.beginGradientFill(GradientType.LINEAR, [0x94e4fc, 0x4ac3e8], [1, 1], [0,  255], gradientBoxMatrix);			
			g.drawRoundRect(2, 1, width-2, height-1, 6, 6);
	        g.endFill();			
			
			var innerShadow:DropShadowFilter = new DropShadowFilter();
			innerShadow.inner = true;
			innerShadow.angle = 60;
			innerShadow.distance = 4;
			innerShadow.blurX = 3;
			innerShadow.blurY = 6;
			innerShadow.alpha = 0.6;
			
			var innerGlow:GlowFilter = new GlowFilter();
			innerGlow.inner = true;
			innerGlow.blurX = 2;
			innerGlow.blurY = 2;
			innerGlow.color = 0xffffff;
			innerGlow.alpha = 0.45;
						
			indicator.filters=[innerGlow, innerShadow];
			*/
	        var g:Graphics = Sprite(indicator).graphics;
	        g.clear();
	        
	        var scaleFactor:Number = width / 284;
	        var matrix:Matrix = new Matrix();
	        matrix.scale(scaleFactor, 1);

	        var indicatorBmp:Bitmap = new selectedIndicator() as Bitmap;
	        
			g.beginBitmapFill(indicatorBmp.bitmapData, matrix, false, true);
	        g.drawRoundRect(2, 1, width-2, height-1, 6, 6);
	        g.endFill();
	        
	        indicator.x = x;
	        indicator.y = y;
	        
	    }
	    override protected function drawHighlightIndicator(
	                                indicator:Sprite, x:Number, y:Number,
	                                width:Number, height:Number, color:uint,
	                                itemRenderer:IListItemRenderer):void
	    {
	    	
	        var g:Graphics = Sprite(indicator).graphics;
	        g.clear();
	        
	        var gradientBoxMatrix:Matrix = new Matrix();
			gradientBoxMatrix.createGradientBox(width,height, Math.PI/2, 0, 0);
//			g.lineGradientStyle(GradientType.LINEAR, [0x1096c3, 0x1096c3], [1, 1], [0,  255], gradientBoxMatrix);
//			g.beginGradientFill(GradientType.LINEAR, [0x94e4fc, 0x4ac3e8], [1, 1], [0,  255], gradientBoxMatrix);			
			g.beginGradientFill(GradientType.LINEAR, [0xf8b738, 0xe06f19], [1, 1], [0,  255], gradientBoxMatrix);			
			g.drawRoundRect(2, 1, width-2, height-1, 6, 6);
	        g.endFill();			
			
			var innerShadow:DropShadowFilter = new DropShadowFilter();
			innerShadow.angle = 90;
			innerShadow.distance = 5;
			innerShadow.blurX = 0;
			innerShadow.blurY = 8;
			innerShadow.alpha = 0.75;
			
			var innerGlow:GlowFilter = new GlowFilter();
			innerGlow.inner = true;
			innerGlow.blurX = 2;
			innerGlow.blurY = 2;
			innerGlow.color = 0xffffff;
			innerGlow.alpha = 0.45;
						
			indicator.filters=[innerGlow, innerShadow];
	        
	        indicator.x = x;
	        indicator.y = y;
	    }
		
	}
}